<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ModifyAuthorizationRequestTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('authorization_requests', function(Blueprint $blueprint) {
            $blueprint->renameColumn('name', 'contact_name');
            $blueprint->renameColumn('email', 'contact_email');
            $blueprint->renameColumn('phone', 'contact_phone');

            $blueprint->timestamp('authorize_start')->comment('授权起始时间');
            $blueprint->timestamp('authorize_stop')->comment('授权终止时间');

            $blueprint->tinyInteger('status')->unsigned()->comment('申请状态，分别有 0 - 拒绝，1 - 申请中，2 - 已授权');

            $blueprint->dropColumn('store_id');
            $blueprint->dropUnique('authorization_requests_provider_id_purchaser_id_unique');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('authorization_requests', function(Blueprint $blueprint) {
            $blueprint->renameColumn('contact_name', 'name');
            $blueprint->renameColumn('contact_email', 'email');
            $blueprint->renameColumn('contact_phone', 'phone');

            $blueprint->dropColumn('authorize_start');
            $blueprint->dropColumn('authorize_stop');

            $blueprint->dropColumn('status');

            $blueprint->integer('store_id');
            $blueprint->unique(['provider_id', 'purchaser_id']);
        });
    }
}
